package demo.activity;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Toast;
import demo.zandroid.R;

/**
 * AlphaAnimation
 * RotateAnimation
 * ScaleAnimation
 * TranslateAnimation
 */
public class AnimationDemo extends Activity implements OnClickListener {

	private Button button1, button2;
	private Animation anim_in, anim_out;
	private Animation anim_left, anim_right;

	private AlphaAnimation alpha_in, alpha_out;
	
	@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_animation);

		button1 = (Button) findViewById(R.id.button1);
		button2 = (Button) findViewById(R.id.button2);

		anim_in = AnimationUtils.loadAnimation(this,
				R.anim.translate_top_to_bottom);
		anim_out = AnimationUtils.loadAnimation(this,
				R.anim.translate_bottom_to_top);
		anim_left = AnimationUtils.loadAnimation(this,
				R.anim.translate_left_to_right);
		anim_right = AnimationUtils.loadAnimation(this,
				R.anim.translate_right_to_left);
		
		alpha_in = new AlphaAnimation(0.0f, 1.0f);
		alpha_out = new AlphaAnimation(1.0f, 0.0f);
		alpha_in.setDuration(2000);
		alpha_out.setDuration(2000);

		findViewById(R.id.button3).setOnClickListener(this);
		findViewById(R.id.button4).setOnClickListener(this);

		findViewById(R.id.button4).setOnLongClickListener(new OnLongClickListener() {
			@Override
			public boolean onLongClick(View v) {
				Toast.makeText(AnimationDemo.this, "onLongClick()", Toast.LENGTH_LONG).show();
				return true;
			}
		});
		
		ProgressBar pb = (ProgressBar) findViewById(R.id.progress_view);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
			pb.animate().setDuration(800).alpha(1);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button3:
			button1.startAnimation(anim_in);
			button1.setVisibility(View.VISIBLE);
			
			button2.startAnimation(alpha_in);
			//button2.startAnimation(anim_left);
			button2.setVisibility(View.VISIBLE);
			break;
		case R.id.button4:
			button1.startAnimation(anim_out);
			button1.setVisibility(View.INVISIBLE);
			
			button2.startAnimation(alpha_out);
			//button2.startAnimation(anim_right);
			button2.setVisibility(View.INVISIBLE);
			break;
		}

	}

}

